﻿using Common.Interfaces;
using Domain.Exceptions;

namespace Domain.ValueObjects
{
    public class RealName : ValueObject
    {
        public string Value { get; }

        private RealName(string value) => Value = value;

        public static RealName Create(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new InvalidRealNameExcption("姓名不能为空。");

            name = name.Trim();
            if (name.Length is < 1 or > 10)
                throw new InvalidRealNameExcption("姓名长度必须在 1 到 10 个字符之间。");

            return new(name);
        }

        protected override IEnumerable<object> GetEqualityComponents()
        {
            yield return Value;
        }

        public static implicit operator string(RealName value) => value.Value;
    }
}
